<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="__ROOT__/Public/Admin/css/shortcut icon" href="favicon.ico">
    <link href="__ROOT__/Public/Admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__ROOT__/Public/Admin/css/animate.css" rel="stylesheet">
    <link href="__ROOT__/Public/Admin/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="__ROOT__/Public/Admin/js/plugins/cityPicker/city-picker.css" rel="stylesheet">
    <link href="__ROOT__/Public/Admin/js/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <link href="__ROOT__/Public/Admin/css/edit.css" rel="stylesheet"/>

<style>

</style>
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <form class="form-horizontal m-t js-ajax-forms" id="signupForm" action="" method="post" enctype="multipart/form-data">
            <input type="hidden" name="ID" value="{$editdata['ID']}">
            <div class="col-sm-12  col-md-offset-2">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">合同相关方 * </label>
                                <div class="col-sm-5">
                                  <select class="form-control" id="PartnerType" name="PartnerType" aria-required="true" aria-invalid="true" class="error">
                                        <option value="">请选择相关方类型</option>
                                        <foreach name="data.selectlist.PartnerType" item="vo">
                                            <option <if condition="$vo.ID eq $editdata['PartnerType']"> selected  disabled </if> value="{$vo.ID}">{$vo.Name}</option>
                                        </foreach>
                                    </select>
                                </div>
                            </div>

                            <div class="form-group" id='mph' style="display: none;">
                                <label class="col-sm-3 control-label"></label>
                                <div class="col-sm-5">
                                    <input id="mp" name="mp" disabled class="form-control" type="text" value="">
                                </div>
                            </div>

                            <div class="form-group" >
                                <label class="col-sm-3 control-label"> 选择相关组织</label>
                                <div class="col-sm-4">
                                    <input id="CPIDName" name="CPIDName" class="form-control selector-icon" type="text" aria-required="true" aria-invalid="true" class="error" value="{$editdata.CPIDName}">
                                    
                                </div>
                                <input type="hidden" id='CPID' name='CPID' value=""></input>
                            </div>
                   
                            <div class="form-group">
                                <div class="col-sm-6 col-sm-offset-3">
                                    <button class="btn btn-primary keep" type="submit">添加</button>
                                </div>
                            </div>
                        
                    </div>
                </div>
            </div>
           
            </form>
        </div>
    </div>
    

    

    <script src="__ROOT__/Public/Admin/js/jquery.min.js"></script>
    <script src="__ROOT__/Public/Admin/js/bootstrap.min.js"></script>
    <script src="__ROOT__/Public/Admin/js/plugins/layer/laydate/laydate.js"></script>
    <script src="__ROOT__/Public/Admin/js/plugins/layer/layer.min.js"></script>
    <script src="__ROOT__/Public/Admin/js/plugins/validate/jquery.validate.min.js"></script>
    <script src="__ROOT__/Public/Admin/js/ajaxForm.js"></script>
    <script src="__ROOT__/Public/Admin/js/plugins/sweetalert/sweetalert.min.js"></script>
    </script>
</body>

<script type="text/javascript">
     var form = $('#signupForm');
     var icon = "<i class='fa fa-times-circle'></i>";
     var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
     var m=parent.$('#multipart').val();
    var mp=new Array(8)
        mp[0]="丙"
        mp[1]="丁"
        mp[2]="戊"
        mp[3]="己"
        mp[4]="庚"
        mp[5]="辛"
        mp[6]="壬"
        mp[7]="癸"

     form.validate({
                //验证规则
                rules: {
                    PartnerType: {
                        required: true
                    },
                    Name: {
                        required: true
                    }
                },
                //验证未通过提示消息
                messages: {
                    PartnerType:{
                        required: icon + "相关单位类型"
                    },
                    Name:{
                        required: icon + "相关单位名称"
                    }
                },
                //验证通过，提交表单
                submitHandler : function(forms) {
                    var t = $(form).serializeArray();
                    var y={};
                    for (var item in t) {
                      y[t[item].name] = t[item].value;
                    }
                    var v = JSON.stringify(y);
                    var name=$('#CPIDName').val();
                    var mp=$('#mp').val();
                    if(mp.length>0){
                        var mph='<b class="pxx">'+mp+'</b>';
                    }else{
                        var mph='';
                    }
                    var cat=$('#PartnerType').find("option:selected").text();
                    var btn='<div class="badge badge-success"  style="margin-right:10px"><b>'+cat+'</b> '+mph+'&nbsp:&nbsp'+name+'&nbsp<i style="cursor:pointer" onclick="cpdelete(this)" class="fa fa-times-circle"></i>';
                    var hideipt="<input type='hidden' name='ContractPartnerList[]' value='"+v+"'></div>";
                    parent.$('#ContractPartnerList').append(btn+hideipt);
                    parent.$('#multipart').val(parseInt(m)+1);
                    parent.layer.close(index);
                    return false;
                   
                }
            });
    

    $("#PartnerType").change(function(){
        var v=$(this).val();
        if(v==2){
            //var m=parent.$('#multipart').val();
            $('#mp').val(mp[m]+'方')
            $('#mph').show();
        }else{
            $('#mp').val('');
            $('#mph').hide();
        }
    });



    $('#CPIDName').on('click', function(){
        layer.open({
                title:'选择相关企业',
                type: 2,
                area: ['850px', '600px'],
                fixed: false, //不固定
                maxmin: true,
                content: '/index.php?m=Admin&c=Contract&a=Customerselect&type=CPID'
            });
    });


    //var PartnerType=parent.$('#PartnerType').val();



</script>

</html>
